package com.changgou.order.controller;

import com.changgou.entity.Result;
import com.changgou.order.feign.CartFeign;
import com.changgou.order.pojo.Order;
import com.changgou.order.pojo.OrderItem;
import com.changgou.user.feign.AddressFeign;
import com.changgou.user.pojo.Address;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author wz
 * @company 公司
 * @create 2020-04-07 11:08
 */
@Controller
@CrossOrigin
@RequestMapping(value = "/worder")
public class OrderController {

    @Autowired
    private CartFeign cartFeign;


    @Autowired
    private AddressFeign addressFeign;

    @RequestMapping("/ready/order")
    public String readyOrder(Model model) {
        List<Address> addressList = addressFeign.list().getData();
        Map map = cartFeign.list();
        List<OrderItem> orderItemList = (List<OrderItem>) map.get("orderItemList");
        Integer totalMoney = (Integer) map.get("totalMoney");
        Integer totalNum = (Integer) map.get("totalNum");
        return "order";
    }

    @PostMapping("/add")
    public Result add(@RequestBody Order order){
        Result result = cartFeign.add(order);

        return result;
    }

    @GetMapping("/toPage")
    public String toPayPage(String orderId,Model model){
        //获取订单相关信息
        return "pay";
    }
}
